﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DX.CRC.Common.Entities;
using WxStockWinSvc.Models.Entities;
using System.Data;
using System.Configuration;

namespace WxStockWinSvc.Commons
{
    static class CommonUtil
    {
        internal static int QoCollOnceCount = Convert.ToInt32(ConfigurationManager.AppSettings["QoCollOnceCount"]);
        internal static int LoadStockThreadCount = Convert.ToInt32(ConfigurationManager.AppSettings["LoadStockThreadCount"]);
        internal static string RunTime = ConfigurationManager.AppSettings["RunTime"];

        internal static QueryObject CreateTextQO()
        {
            return new QueryObject4WxStock() { CommandType = CommandType.Text, };
        }

        internal static QueryObject CreateSPQO()
        {
            return new QueryObject4WxStock() { CommandType = CommandType.StoredProcedure, };
        }

        internal static List<DataRow> xTake(this DataTable dataTable, int count)
        {
            List<DataRow> listRow = new List<DataRow>();

            for (int i = 0; i < Math.Min(count, dataTable.Rows.Count); i++)
                listRow.Add(dataTable.Rows[i]);

            return listRow;
        }

        internal static void xRemoveRange(this DataTable dataTable, int count)
        {
            for (int i = 0; i < Math.Min(count, dataTable.Rows.Count); i++)
                dataTable.Rows.RemoveAt(0);
        }
    }
}
